const path = require('path')
const resolve = (dir) => require('path').join(__dirname, dir)
const TransformModulesPlugin = require('webpack-transform-modules-plugin')
module.exports = {
  mode: 'universal',
  /*
   ** Headers of the page
   */
  head: {
    title: process.env.npm_package_name || '',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      {
        hid: 'description',
        name: 'description',
        content: process.env.npm_package_description || ''
      }
    ],
    link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },{ rel: 'stylesheet', type: 'text/css', href: 'https://unpkg.com/cube-ui/lib/cube.min.css' }]
  },
  /*
   ** Customize the progress-bar color
   */
  loading: { color: '#fff' },
  /*
   ** Global CSS
   */
  css: ['reset.css', 'flex.css', 'vant/lib/index.less'],
  /*
   ** Plugins to load before mounting the App
   */
  plugins: ['@/plugins/vant','@/plugins/cube'],
  /*
   ** Nuxt.js dev-modules
   */
  buildModules: [
    // Doc: https://github.com/nuxt-community/eslint-module
    '@nuxtjs/eslint-module',
    // Doc: https://github.com/nuxt-community/stylelint-module
    '@nuxtjs/stylelint-module'
  ],
  /*
   ** Nuxt.js modules
   */
  modules: [
    // Doc: https://axios.nuxtjs.org/usage
    '@nuxtjs/axios'
  ],
  /*
   ** Axios module configuration
   ** See https://axios.nuxtjs.org/options
   */
  axios: {},
  /*
   ** Build configuration
   */
  build: {
    transpile: ['cube-ui'],
    loaders: {
      stylus: {
        'resolve url': true,
        import: [path.resolve(__dirname, './assets/theme')]
      }
    },
    extend(config) {
      config.resolve.alias['cube-ui'] = 'cube-ui/lib'
    },
    plugins: [
      new TransformModulesPlugin()
    ],
    /*
     ** You can extend webpack config here
     */
    postcss: {
      postcss: {
        plugins: {
          'postcss-pxtorem':{
            rootValue: 75,
            unitPrecision:7,
            propList: ['*'],
            selectorBlackList:["van-"]
          },
          'postcss-url':false,
          'postcss-nested': {},
          'cssnano': { preset: 'default' },
          'postcss-assets':{
            relative:true,
            loadPaths: ['assets/images']
          }
        },
        preset: {
          stage:2,
          autoprefixer: {
            grid: true,
            overrideBrowserslist: [
              //'last 2 versions',
              'Android >= 4.0',
              'iOS >= 7'
            ]
          },
          importFrom:['assets/less/common.less']
        }
      }
    },
    // babel: {
    //   plugins: [
    //     [
    //       'import',
    //       {
    //         libraryName: 'vant',
    //         libraryDirectory: 'es',
    //         style: false
    //       },
    //       'vant'
    //     ]
    //   ]
    // },
    loaders: {
      less: {
        javascriptEnabled: true,
        data: `
          @import "@/assets/less/common.less";
        `,
        modifyVars: {
          hack: `true; @import "${resolve('./assets/less/common')}";`
        }
      }
    },
    extend(config, { isDev, isClient }) {}
  }
}
